package com.sfh.gd.service.impl;


import cn.dev33.satoken.util.SaResult;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.sfh.gd.converter.SysConverter;
import com.sfh.gd.domain.dto.SysLoginDTO;
import com.sfh.gd.domain.entity.SysUseDO;
import com.sfh.gd.domain.vo.SysUserVO;
import com.sfh.gd.exception.BusinessException;
import com.sfh.gd.mapper.SysUserMapper;
import com.sfh.gd.service.SysService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;


@Slf4j
@Service
@RequiredArgsConstructor
public class SysServerImpl extends ServiceImpl<SysUserMapper, SysUseDO> implements SysService {

    private final SysConverter sysConverter;
    private final SysUserMapper  sysUserMapper;

    @Override
    public SaResult login(SysLoginDTO dto) {
        // 1. 查询用户
        SysUseDO userDO = sysUserMapper.selectByUsername(dto.getSysName());
        if (userDO == null) {
            throw new BusinessException("账号不存在");
        }
        if (!userDO.getPassword().equals(dto.getSysPassword())){
            throw new BusinessException("密码不正确");
        }
        SysUserVO userVO = sysConverter.doToVo(userDO);

        return SaResult.data(userVO);
    }

}
